#ifndef __BYTECODE_BUFFER_H__
#define __BYTECODE_BUFFER_H__

#include "rstring.h"
#include "bytecode.h"
#include "redobject.h"

typedef struct _bytecode_buffer_t
{
	int			  pc;
	int			  ref;
	int			  size;
	int			  count;
	bytecode_t	**bucket;
} bytecode_buffer_t;

RED_EXPORT void bytecode_buffer_ref(bytecode_buffer_t *self);
RED_EXPORT void bytecode_buffer_unref(bytecode_buffer_t *self);
RED_EXPORT void bytecode_buffer_release(bytecode_buffer_t **self);

RED_EXPORT bytecode_buffer_t *bytecode_buffer_create(void);

RED_EXPORT void bytecode_buffer_free(bytecode_t *code, int size);
RED_EXPORT bytecode_t *bytecode_buffer_emit(bytecode_buffer_t *self, opcode_t opcode, int lineno, int position);
RED_EXPORT RedObject *bytecode_buffer_assemble(bytecode_buffer_t *self, rstring_t *fname, rstring_t *source, RedObject *module);

#endif /* __BYTECODE_BUFFER_H__ */
